#include "mywidget.h"
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMenu>
#include <QIcon>
#include <QGroupBox>
#include <QCheckBox>
#include <QRadioButton>
MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
{
    setWindowTitle(tr("Button Group"));
    btn1 = new QPushButton(tr("&Hello"), this);
    btn2 = new QPushButton(tr("&Help"), this);
    btn3 = new QPushButton(tr("&Zoom"), this);
    btn1->setCheckable(true);
    btn2->setFlat(true);
    btn2->setIcon(QIcon(":/open.png"));

    QMenu *menu = new QMenu(this);
    menu->addAction(QIcon(":/open.png"),tr("放大"));
    btn3->setMenu(menu);

    QGroupBox *groupBox1 = new QGroupBox(tr("Check Box"), this);
    QCheckBox *runBox = new QCheckBox(tr("Run"), groupBox1);
    runBox->setChecked(true);
    QCheckBox *ballBox = new QCheckBox(tr("Football"), groupBox1);
    QCheckBox *swimBox = new QCheckBox(tr("Swimming"), groupBox1);
    QVBoxLayout *vBoxlayout1 = new QVBoxLayout;
    vBoxlayout1->addWidget(runBox);
    vBoxlayout1->addWidget(ballBox);
    vBoxlayout1->addWidget(swimBox);
    groupBox1->setLayout(vBoxlayout1);

    QGroupBox *groupBox2 = new QGroupBox(tr("Radio Box"), this);
    QRadioButton *betterRadio = new QRadioButton(tr("Better"), groupBox2);
    betterRadio->setChecked(true);
    QRadioButton *normalRadio = new QRadioButton(tr("Normal"), groupBox2);
    QRadioButton *badRadio = new QRadioButton(tr("Bad"), groupBox2);
    QVBoxLayout *vBoxlayout2 = new QVBoxLayout;
    vBoxlayout2->addWidget(betterRadio);
    vBoxlayout2->addWidget(normalRadio);
    vBoxlayout2->addWidget(badRadio);
    groupBox2->setLayout(vBoxlayout2);

    QHBoxLayout *uplayout = new QHBoxLayout;
    uplayout->addWidget(btn1, 0, Qt::AlignCenter);
    uplayout->addWidget(btn2, 0, Qt::AlignCenter);
    uplayout->addWidget(btn3, 0, Qt::AlignCenter);
    QHBoxLayout *downlayout = new QHBoxLayout;
    downlayout->addWidget(groupBox1);
    downlayout->addWidget(groupBox2);
    QVBoxLayout *mainlayout = new QVBoxLayout;
    mainlayout->addLayout(uplayout);
    mainlayout->addLayout(downlayout);
    setLayout(mainlayout);
    connect(btn1, SIGNAL(toggled(bool)),
            this, SLOT(setButtonStatue(bool)));
}

MyWidget::~MyWidget()
{

}

void MyWidget::setButtonStatue(bool checked)
{
    if (checked)
        btn1->setText(tr("&World!"));
    else
        btn1->setText(tr("&Hello"));
}
